#include "CreatureObject.h"

#include <OgreRoot.h>
#include <OgreEntity.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>

#include "OgreFramework.h"
#include "GameState.h"


#include "IA.h"

CreatureObject::CreatureObject():
MovableObject()
{
    //ctor
    isWalking=false;
    m_waypoints.clear();

    m_ia=0;

}

CreatureObject::~CreatureObject()
{
    //dtor
    if (!m_ia)delete m_ia;
}
/** @brief getType
  *
  * @todo: document this function
  */
OBJ_TYPE CreatureObject::getType()
{
    return OBJ_TYP_CREATURE;
}

/** @brief init
  *
  * @todo: document this function
  */
void CreatureObject::init()
{
    /*
    Ogre::SceneManager *sceneMgr = OgreFramework::getSingletonPtr()->m_pRoot->getSceneManager("GameSceneMgr");

    m_node = sceneMgr->getRootSceneNode()->createChildSceneNode();
    m_entity = sceneMgr->createEntity("creature_"+Ogre::StringConverter::toString(m_id++), "penguin.mesh");

    m_node->attachObject(m_entity);
    m_node->setInheritOrientation(false);

    setYOffset(0.1);

        m_ia = new IA(this);

   // IAState *state2 = m_ia->createState(IA::STA_BRING);



    IAState* state = m_ia->createState(IA::STA_EXPLORE);
    state->setParentCreature(this);
    m_ia->changeState(state);

  //  m_ia->changeState();


// Set animation blend mode to additive / cumulative.
    m_entity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
    m_entity->setMaterialName("Examples/monsterSkin");

    m_node->setScale(Ogre::Vector3(0.01,0.01,0.01));

    m_entity->setQueryFlags(QUERY_CHARACTER);

   // m_animCreature.setPosition(Ogre::Vector3(m_position.x,m_Yoffset,m_position.y));
    m_animCreature->init();


    m_node->setPosition(Ogre::Vector3(m_position.x,m_Yoffset,m_position.y));




    //m_waypoints.clear();
*/
}

/** @brief update
  *
  * @todo: document this function
  */
void CreatureObject::update(double timeSinceLastFrame)
{
// Figure out the direction and distance we need to walk until the target

/*
     Ogre::Vector2 direction;
    float distance;

    m_ia->update(timeSinceLastFrame);


    if (m_waypoints.size()>0)
    {
        isWalking = true;
        m_animCreature->update( timeSinceLastFrame);
        walkTo((*m_waypoints.begin()));

//    OgreFramework::getSingletonPtr()->m_pLog->logMessage("Creature object update walk to");


    }
    else
    {
        isWalking = false;

    }



*/
}

/** @brief clear
  *
  * @todo: document this function
  */
void CreatureObject::clear()
{

}





